package com.jiazhong.controller;

import com.alibaba.fastjson.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/first")
public class FirstController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 收--请求
        request.setCharacterEncoding("UTF-8");
        String message = request.getParameter("message");
        System.out.println("接受了用户发送过来的数据:" + message);
        // 发--响应
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        JsonResult result = new JsonResult(message);
        out.println(JSONArray.toJSON(result));
    }
}
